import yaml
import os
import json

def read_yaml(path: str) -> dict:
    with open(path, 'r') as f:
        data = yaml.safe_load(f)
    return data

def read_json(path):
    with open(path, 'r') as f:
        return json.load(f)

def dump_json(path, data, force=False, verbose=False):
    """ write data to json file of path
    :param path: path of json file, should include json file name in the path
    :param data: data to write
    :param force: if force writing if path exists
    """
    if force or not os.path.exists(path):
        with open(path, 'w') as f:
            json.dump(data, f, indent=2, ensure_ascii=False)
            if verbose:
                print(f"INFO: {path} is written")
    else:
        print(f"INFO: {path} already exist, json file un-written!")

